import axios from 'axios';

const request = axios.create({
  baseURL: "http://api-toutiao-web.itheima.net/mp/v1_0/"
})

request.interceptors.request.use(config => {
  // 所有请求都会经过这里
  const user = JSON.parse(window.localStorage.getItem('user'));

  if(user) {
    config.headers.Authorization = `Bearer ${user.token}`;
  }
  return config;
}, err => {
  // 请求失败经过这里
  return err;
})

export default request;